package com.example.jdimust.main;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.example.jdimust.R;
import com.example.jdimust.about.AboutActiity;
import com.example.jdimust.login.LoginActivity;
import com.example.jdimust.main.ui.Dataquery.DataqueryFragment;
import com.example.jdimust.main.ui.home.HomeFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<String> mTabTitle = new ArrayList<>();
    private List<Fragment> mViewPager = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BottomNavigationView navView = findViewById(R.id.nav_view);
        Intent intent = getIntent();
        String res_in_all = intent.getStringExtra("login_reslust");

        mTabTitle.add("HomeFragment");
        mTabTitle.add("DashboardFragment");
        mViewPager.add(new DataqueryFragment(res_in_all));
        mViewPager.add(new HomeFragment(res_in_all));
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView, navController);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu,menu);
        return true;
    }
    /**
     *菜单的点击事件
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){
            case R.id.chageuser:
                Toast.makeText(this, "正在切换用户！", Toast.LENGTH_SHORT).show();
//                Intent intent = new Intent(MainActivity.this, LoginActivity.class);//从SpendingActivity页面跳转至ExpenseProcesActivity页面
                startActivity(new Intent(MainActivity.this, LoginActivity.class));
                break;
            case R.id.about:
//                Intent intentq = new Intent(MainActivity.this, AboutActiity.class);//从SpendingActivity页面跳转至ExpenseProcesActivity页面
                startActivity(new Intent(MainActivity.this, AboutActiity.class));
                break;
            default:
                break;
        }

        return true;
    }

}